//
//  RHLocalPackItemCell.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2024/4/8.
//

#import "RHLocalPackItemCell.h"
@interface RHLocalPackItemCell()
@property (nonatomic, strong) UIImageView *stateImg;

@property (nonatomic, strong) QMUILabel *nameLab;

@property (nonatomic, strong) QMUILabel *packNoLab;//SN

@property (nonatomic ,strong) QMUILabel *softContentLab;

@property (nonatomic ,strong) QMUILabel *loopContentLab;

@property (nonatomic ,strong) QMUILabel *remainContentLab;

@end
@implementation RHLocalPackItemCell
-(instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame]){
        [self setupUI];
    }
    return self;
}

- (void)setPackModel:(RHLocalDevPackModel *)packModel
{
    _packModel = packModel;
    self.nameLab.text = packModel.title;
    self.packNoLab.text = ValidNullDataToString(packModel.sn, @"--");
    self.softContentLab.text = packModel.softWare;
    self.loopContentLab.text = packModel.cycleCount;
    self.remainContentLab.text = [NSString stringWithFormat:@"%@Ah",ValidNullDataToString(packModel.remainCap, @"--")];
    
    
    if ([self.packModel.maxTemp floatValue] <= 40 && [self.packModel.maxTemp floatValue] >= 20) {
        self.stateImg.image = [UIImage imageNamed:@"local_cell_normal"];
    }else{
        self.stateImg.image = [UIImage imageNamed:@"local_cell_fault"];
    }
}

-(void)setupUI
{
    kWeakSelf;
    self.contentView.backgroundColor = CFTabViewBgColor;
    UIView *bgView = kView;
    bgView.backgroundColor = [UIColor whiteColor];
    bgView.layer.cornerRadius = 8;
    bgView.layer.masksToBounds = YES;
    [self.contentView addSubview:bgView];
    self.bgView = bgView;
    
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsZero);
    }];
    
    _stateImg = [[UIImageView alloc]init];
    _stateImg.layer.cornerRadius = 5;
    _stateImg.layer.masksToBounds = YES;
    [bgView addSubview:_stateImg];
    [_stateImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(kScaleW(20));
       
        make.left.top.mas_offset(15);
    }];
    
    _nameLab = [[QMUILabel alloc]init];
    _nameLab.font = [UIFont systemFontOfSize:14];
    _nameLab.textAlignment = NSTextAlignmentLeft;
    _nameLab.textColor = kColorRGBA(0, 0, 0, 0.8);
    [bgView addSubview:_nameLab];
    [_nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.stateImg.mas_right).offset(8);
        make.top.mas_offset(5);
    }];
    
    QMUILabel *packNoTitleLab = [QMUILabel labelWithText:@"SN:" font:kSYSTEMFONT(10) textColor:kColorRGBA(0, 0, 0, 0.6)];
    [bgView addSubview:packNoTitleLab];
    CGFloat labWidth = [packNoTitleLab.text getStringWidthFont:packNoTitleLab.font limitHeight:20];
    [packNoTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.nameLab);
        make.top.equalTo(weakSelf.nameLab.mas_bottom).offset(5);
        make.width.offset(labWidth);
    }];
    
    _packNoLab = [[QMUILabel alloc]init];
    _packNoLab.text = @"--";
    _packNoLab.font = [UIFont systemFontOfSize:10];
    _packNoLab.textAlignment = NSTextAlignmentLeft;
    _packNoLab.textColor = kColorRGBA(0, 0, 0, 0.6);
    _packNoLab.numberOfLines = 2;
    [bgView addSubview:_packNoLab];
  
    [_packNoLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(packNoTitleLab.mas_right);
        make.top.equalTo(packNoTitleLab);
        make.right.mas_offset(-5);
    }];
    
    UIView *line = kView;
    line.backgroundColor = kRGB(225, 225, 225);
    [bgView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(0);
        make.right.mas_offset(0);
        make.top.equalTo(weakSelf.packNoLab.mas_bottom).offset(10);
        make.height.offset(1);
    }];
   
    UIView *bottomView = kView;
    [bgView addSubview:bottomView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_offset(0);
        make.top.equalTo(line.mas_bottom);
    }];
    
    //软件版本
    QMUILabel *softTitleLab = [QMUILabel labelWithText:[NSString stringWithFormat:@"%@:",@"软件版本".rh_localized] font:kSYSTEMFONT(10) textColor:kColorRGBA(63, 68, 67, 0.6)];
    [softTitleLab sizeToFit];
    [bottomView addSubview:softTitleLab];
  
    [softTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.top.mas_offset(0);
        make.width.mas_offset(softTitleLab.width+1);
    }];
    
    _softContentLab = [QMUILabel labelWithFont:kSYSTEMFONT(10) textColor:kColorRGBA(63, 68, 67, 0.8) textAligment:NSTextAlignmentRight];
    _softContentLab.text = @"--";
    [bottomView addSubview:_softContentLab];
    [_softContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(softTitleLab.mas_right);
        make.right.mas_offset(-15);
        make.centerY.equalTo(softTitleLab);
    }];
    
    //循环次数
    QMUILabel *loopTitleLab = [QMUILabel labelWithText:[NSString stringWithFormat:@"%@:",@"循环次数".rh_localized] font:kSYSTEMFONT(10) textColor:kColorRGBA(63, 68, 67, 0.6)];
    [loopTitleLab sizeToFit];
    [bottomView addSubview:loopTitleLab];
  
    [loopTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.top.equalTo(softTitleLab.mas_bottom).offset(0);
        make.centerY.mas_offset(0);
        make.width.offset(loopTitleLab.width+1);
        make.height.offset(loopTitleLab.height+1);
    }];
    
    _loopContentLab = [QMUILabel labelWithFont:kSYSTEMFONT(10) textColor:kColorRGBA(63, 68, 67, 0.8) textAligment:NSTextAlignmentRight];
    _loopContentLab.text = @"--";
    [bottomView addSubview:_loopContentLab];
    [_loopContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(loopTitleLab.mas_right);
        make.right.mas_offset(-15);
        make.centerY.equalTo(loopTitleLab);
    }];
    
    //剩余电量
    QMUILabel *remainTitleLab = [QMUILabel labelWithText:[NSString stringWithFormat:@"%@:",@"剩余容量".rh_localized] font:kSYSTEMFONT(10) textColor:kColorRGBA(63, 68, 67, 0.6)];
    [remainTitleLab sizeToFit];
    [bottomView addSubview:remainTitleLab];
  
    [remainTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.top.equalTo(loopTitleLab.mas_bottom).offset(0);
        make.width.mas_offset(remainTitleLab.width+1);
        make.bottom.mas_offset(0);
    }];
    
    _remainContentLab = [QMUILabel labelWithFont:kSYSTEMFONT(10) textColor:kColorRGBA(63, 68, 67, 0.8) textAligment:NSTextAlignmentRight];
    _remainContentLab.text = @"--";
    [bottomView addSubview:_remainContentLab];
    [_remainContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(remainTitleLab.mas_right);
        make.right.mas_offset(-15);
        make.centerY.equalTo(remainTitleLab);
    }];
}
@end
